package com.yehun.admin.controller;

import com.yehun.admin.models.PageConfig;
import com.yehun.entity.Category;
import com.yehun.entity.PagerEntity;
import com.yehun.service.CategoryService;
import com.yehun.utils.ParamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "category")
public class CategoryController extends BaseController {

    @Autowired
    private CategoryService categoryService;

    @RequestMapping(value = { "", "index", "list" }, name = "分类列表")
    public String list() {
        return "category/list";
    }

    @ResponseBody
    @RequestMapping(value = { "listAjax" }, name = "分类列表数据获取")
    public PageConfig<Category> listAjax() {
        int pageIndex = ParamUtils.getPageIndex();
        int pageSize = ParamUtils.getPageSize();
        PagerEntity<Category> pager = categoryService.listPager(pageIndex, pageSize);
        return PageConfig.mapper(pager);
    }

}
